﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;

namespace OnlineBusTicket
{
    public partial class DelTour : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private bool CheckTourExist()//fixed
        {
            bool check = false;
            string userid = txtBusId.Text;
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
            SqlCommand cmd = new SqlCommand("Select * from Buslist", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (userid == dr.GetString(0))
                {
                    check = true;
                    break;
                }
            }
            con.Close();
            return check;
        }

        protected void btnSave_Click(object sender, EventArgs e)//fixed
        {
            string id = txtBusId.Text;
            if (CheckTourExist())
            {
                txtBusId.Text = ("UserId has been exist...");
            }
            else
            {
                SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
                con.Open();

                SqlCommand cmd = new SqlCommand("DELETE FROM Buslist WHERE BusListId='" + id + "'", con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Redirect("Buslist.aspx");
            }
        }
    }
}